import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;

public class LongPlayerScreen extends Canvas {

	LongPlayer midlet;
	private String time = "";
	private int totalTime;
	private int actualTime;

	public LongPlayerScreen(LongPlayer aMidlet) {
		super();
		midlet = aMidlet;
	}

	protected void paint(Graphics g) {
		int screenWidth = 240;
		g.setColor(0x000000);
		g.fillRect(0, 0, screenWidth, 250);
		g.setColor(0xffffff);
		g.drawString(time, screenWidth / 2,
				(248 - g.getFont().getHeight()) / 2, Graphics.HCENTER
						| Graphics.TOP);

		g.setColor(0xFF3300);
		int sideGap = 20;
		int rectHeight = 20;
		g.drawRect(sideGap, 150, screenWidth - sideGap * 2, rectHeight);
		int innerGap = 2;
		g.fillRect(sideGap + innerGap, 150 + innerGap, (screenWidth - sideGap
				* 2 - innerGap - 1)
				* actualTime / totalTime, rectHeight - innerGap - 1);
		int blockWidth = 12;
		if (LongPlayer.getState().equals(State.PAUSE)) {
			g.fillRect((screenWidth - blockWidth * 2 - 2) / 2, 200, blockWidth,
					g.getFont().getHeight());

			g.fillRect((screenWidth - blockWidth * 2 - 2) / 2 + blockWidth + 2,
					200, blockWidth, g.getFont().getHeight());
		}
	}

	public void keyPressed(int keyCode) {
		midlet.secureKeyPressed(keyCode);
	}

	public void setTime(String aTime) {
		time = aTime;
	}

	public void setTotalTime(long duration) {
		totalTime = (int) duration / 1000000;
	}

	public void setActualTime(long aTime) {
		actualTime = (int) aTime / 1000000;
	}
}
